import 'package:flutter_app/bean/list_other_problem_entity.dart';
import 'package:flutter_app/manager/UserInfoManager.dart';
import 'package:flutter_app/network/Api.dart';
import 'package:flutter_app/network/ResultData.dart';
import 'package:flutter_app/utils/toast_utils.dart';
import 'package:flutter_app/values/MyColors.dart';
import 'package:flutter_app/widget/watermark/watermark_utils.dart';
import 'package:get/get.dart';

import '../../../../r.dart';
import 'film_detail_state.dart';

class FilmDetailLogic extends GetxController {
  final FilmDetailState state = FilmDetailState();

  late String id;

  String flowStatus = "0";
  List<String> thumbnailPaths = [];
  List<String> sourcePaths = [];

  @override
  void onInit() {
    super.onInit();
    id = Get.arguments;
  }

  @override
  void onReady() {
    super.onReady();
    WatermarkUtils()
        .addWatermark(Get.context!, UserInfoManager().getUserName());

    getOtherProblem(id);
  }

  Future<void> getOtherProblem(String id) async {
    Map<String, dynamic> param = {
      "id": id,
    };
    ResultData resultData = await Api.getOtherProblem(param);
    if (resultData.isSuccess) {
      state.listOtherProblemContent =
          ListOtherProblemContent.fromJson(resultData.data['data']);
      setData();
      update();
    } else {
      toast.show(resultData.data["message"]);
    }
  }

  void setData() {
    flowStatus = state.listOtherProblemContent?.flowStatus ?? "0";

    state.listOtherProblemContent?.fileList?.forEach((element) {
      thumbnailPaths.add(element.thumbnailPath ?? "");
      sourcePaths.add(element.sourcePath ?? "");
    });
  }

  Map getTagObj() {
    var obj = {
      "url": R.assetsImgIcon69,
      "title": "审核中",
      "content": "省直效能办正在核实问题，请耐心等待",
      "textColor": MyColors.FF2763B9,
    };
    switch (flowStatus) {
      case "0":
      case "11":
      case "21":
        obj = {
          "url": R.assetsImgIcon69,
          'title': '审核中',
          'content': '省直效能办正在核实问题，请耐心等待',
          'textColor': MyColors.FF2763B9,
        };
        break;
      case "12":
      case "22":
      case "32":
        obj = {
          "url": R.assetsImgIcon70,
          'title': '未采纳',
          'content': '省直效能办回复：相关部门已经引起重视，正在积极 整改中，所拍内容为治理中的情况，感谢参与！',
          'textColor': MyColors.FF2763B9,
        };
        break;
      case "31":
        obj = {
          "url": R.assetsImgIcon71,
          'title': '已采纳',
          'content': '经核实，事实清晰，感谢您的上报',
          'textColor': MyColors.FF2AAB33,
        };
        break;
    }
    return obj;
  }

  @override
  void onClose() {
    super.onClose();
    WatermarkUtils().removeWatermark();
  }
}
